<template>
	<view v-if="list.length>0" class="">
		<phone-directory :phones="list" @paramClick="selectCityH5"></phone-directory>
	</view>
</template>

<script>
	import {
		cityList
	} from '@/api/api.js';
	import phoneDirectory from '@/components/phone-directory/phone-directory.vue'
	import Cache from '../../utils/cache';
	import { CITY_INFO, LOCATION_CITY_INFO, USER_LOCATION} from '../../config/cache.js'
	
	export default {
		components:{
			phoneDirectory,
		},
		data() {
			return {
				//示例数据
						
				scrollTop: 0,
				indexList: [],
				list: [],
				source: '',
			}
		},
		onLoad(options) {
			var that = this
			uni.showLoading({
				title:'加载中'
			})
			that.source = options.source
		   cityList().then(res => {
              that.list = res.data			  
			  // that.indexList = that.list.map(val => {
			  // 	return val.letter;
			  // })		
			  uni.hideLoading()
		    })
			
		},
		methods:{
			paramClick(e){
			},
			
			selectCityH5(item){
				if(this.source != 'bus'){
					Cache.set(CITY_INFO,{id: item.id,name: item.name,lat: item.lat,lng: item.lng})
					// Cache.set(LOCATION_CITY_INFO,{id: item.id,name: item.cityName,lat: item.lat,lng: item.lng},86400)
					
					
					// uni.switchTab({
					// 	url:"/pages/index/index"
					// })
					var pages = getCurrentPages();
					var prevPage = pages[pages.length - 2]; //上一个页面
					//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
					//uni或者vue用$vm
					prevPage.$vm.selectCityHand = true
					uni.navigateBack({//返回
						delta: 1
					})
				} else{
					Cache.set(CITY_INFO,{id: item.id,name: item.name,lat: item.lat,lng: item.lng})
					// Cache.set(LOCATION_CITY_INFO,{id: item.id,name: item.cityName,lat: item.lat,lng: item.lng},86400)

					// uni.switchTab({
					// 	url:"/pages//real_bus_index/index"
					// })
					var pages = getCurrentPages();
					var prevPage = pages[pages.length - 2]; //上一个页面
					//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
					//uni或者vue用$vm
					prevPage.$vm.selectCityHand = true
					uni.navigateBack({//返回
						delta: 1
					})
				}
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		}
	}
</script>

<style lang="scss" scoped>

</style>